package mxmf.content.code;

import java.text.DecimalFormat;
import java.util.Date;

import org.apache.commons.lang3.time.FastDateFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import mxmf.repository.BaseContentQueryRepository;

@Component
public abstract class AbstractCodeGenerater implements CodeGenerater {

    @Autowired
    private BaseContentQueryRepository baseContentQueryRepository;

    FastDateFormat dateFormat = FastDateFormat.getInstance("yyMMdd");
    DecimalFormat numberFormat = new DecimalFormat("00");

    /**
     * {preType}_YYMMDD+Numbers
     * @param preType
     * @return
     */
    public String createYYMMDDNum(String preType) {
        StringBuffer preCode = new StringBuffer();
        preCode.append(preType).append("_").append(dateFormat.format(new Date()));
        int num = 0;
        while (true) {
            String extCode = numberFormat.format(num++);
            String contentCode = preCode + extCode;
            return contentCode;
        }
    }

}
